package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.CatMassagePush;
import com.happy.cat.project.system.service.ICatMassagePushService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 系统推送Controller
 *
 * @author verne
 * @date 2020-08-07
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/catMassagePush" )
@Api("系统推送 API")
public class CatMassagePushController extends BaseController {

    private final ICatMassagePushService iCatMassagePushService;

    /**
     * 查询系统推送列表
     */
    @ApiOperation(value = "查询系统推送列表",notes = "查询系统推送列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatMassagePush catMassagePush)
    {
        startPage();
        LambdaQueryWrapper<CatMassagePush> lqw = new LambdaQueryWrapper<CatMassagePush>();
        if (StringUtils.isNotBlank(catMassagePush.getTitle())){
            lqw.eq(CatMassagePush::getTitle ,catMassagePush.getTitle());
        }
        if (StringUtils.isNotBlank(catMassagePush.getContent())){
            lqw.eq(CatMassagePush::getContent ,catMassagePush.getContent());
        }
        if (StringUtils.isNotBlank(catMassagePush.getType())){
            lqw.eq(CatMassagePush::getType ,catMassagePush.getType());
        }
        List<CatMassagePush> list = iCatMassagePushService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出系统推送列表
     */
    @ApiOperation(value = "导出系统推送列表",notes = "导出系统推送列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:export')" )
    @Log(title = "系统推送" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatMassagePush catMassagePush) {
        LambdaQueryWrapper<CatMassagePush> lqw = new LambdaQueryWrapper<CatMassagePush>(catMassagePush);
        List<CatMassagePush> list = iCatMassagePushService.list(lqw);
        ExcelUtil<CatMassagePush> util = new ExcelUtil<CatMassagePush>(CatMassagePush. class);
        return util.exportExcel(list, "catMassagePush" );
    }

    /**
     * 获取系统推送详细信息
     */
    @ApiOperation(value = "获取系统推送详细信息",notes = "获取系统推送详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatMassagePushService.getById(id));
    }

    /**
     * 新增系统推送
     */
    @ApiOperation(value = "新增系统推送",notes = "新增系统推送",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:add')" )
    @Log(title = "系统推送" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatMassagePush catMassagePush) {
        return toAjax(iCatMassagePushService.save(catMassagePush) ? 1 : 0);
    }

    /**
     * 修改系统推送
     */
    @ApiOperation(value = "修改系统推送",notes = "修改系统推送",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:edit')" )
    @Log(title = "系统推送" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatMassagePush catMassagePush) {
        return toAjax(iCatMassagePushService.updateById(catMassagePush) ? 1 : 0);
    }

    /**
     * 删除系统推送
     */
    @ApiOperation(value = "删除系统推送",notes = "删除系统推送",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:catMassagePush:remove')" )
    @Log(title = "系统推送" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatMassagePushService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
